package com.jt.controller;

import com.jt.pojo.ImageVO;
import com.jt.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class FileController {

    @Autowired
    private FileService fileService;

    @RequestMapping("/file")
    public String file(MultipartFile fileImage) throws IOException{
        String dirPath="C:/123/images";
        File dirFile=new File(dirPath);
        if (!dirFile.exists()){
            dirFile.mkdirs();
        }
        String fileName=fileImage.getOriginalFilename();
        String filePath=dirPath+"/"+fileName;
        File file=new File(filePath);
        fileImage.transferTo(file);
        return "文件上传成功！！！";
    }

    @RequestMapping("/pic/upload")
    public ImageVO upload(MultipartFile uploadFile){
        return fileService.upload(uploadFile);
    }
}
